package com.galen.manual.entity;

import com.baomidou.mybatisplus.annotation.*;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * 文件记录实体类
 */
@Data
@TableName("file_records")
@Schema(description = "文件记录信息")
public class FileRecord {

    /**
     * 主键ID
     */
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    @Schema(description = "文件记录ID", example = "1234567890123456789")
    private Long id;

    /**
     * 原始文件名
     */
    @TableField("original_filename")
    @Schema(description = "原始文件名", example = "avatar.jpg")
    private String originalFilename;

    /**
     * Minio对象名称
     */
    @TableField("object_name")
    @Schema(description = "Minio对象名称", example = "uploads/1698432000000_1234.jpg")
    private String objectName;

    /**
     * 文件访问URL
     */
    @TableField("file_url")
    @Schema(description = "文件访问URL", example = "http://minio-server:9000/manual-storage/uploads/1698432000000_1234.jpg")
    private String fileUrl;

    /**
     * 文件大小（字节）
     */
    @TableField("file_size")
    @Schema(description = "文件大小（字节）", example = "1024000")
    private Long fileSize;

    /**
     * 文件MIME类型
     */
    @TableField("content_type")
    @Schema(description = "文件MIME类型", example = "image/jpeg")
    private String contentType;

    /**
     * 文件分类
     */
    @TableField("file_category")
    @Schema(description = "文件分类", example = "products")
    private String fileCategory;

    /**
     * 上传用户ID
     */
    @TableField("upload_user_id")
    @Schema(description = "上传用户ID", example = "123456")
    private Long uploadUserId;

    /**
     * 上传用户名
     */
    @TableField("upload_username")
    @Schema(description = "上传用户名", example = "admin")
    private String uploadUsername;

    /**
     * 业务关联ID（如产品ID、Banner ID等）
     */
    @TableField("business_id")
    @Schema(description = "业务关联ID", example = "123456")
    private Long businessId;

    /**
     * 业务类型
     */
    @TableField("business_type")
    @Schema(description = "业务类型", example = "product")
    private String businessType;

    /**
     * 文件状态：0-上传中，1-上传成功，2-上传失败
     */
    @TableField("status")
    @Schema(description = "文件状态", example = "1")
    private Integer status;

    /**
     * 上传IP地址
     */
    @TableField("upload_ip")
    @Schema(description = "上传IP地址", example = "192.168.1.1")
    private String uploadIp;

    /**
     * 用户代理信息
     */
    @TableField("user_agent")
    @Schema(description = "用户代理信息", example = "Mozilla/5.0...")
    private String userAgent;

    /**
     * 错误信息
     */
    @TableField("error_message")
    @Schema(description = "错误信息", example = "上传失败：文件过大")
    private String errorMessage;

    /**
     * 文件哈希值（用于去重）
     */
    @TableField("file_hash")
    @Schema(description = "文件哈希值", example = "d41d8cd98f00b204e9800998ecf8427e")
    private String fileHash;

    /**
     * 是否重复文件
     */
    @TableField("is_duplicate")
    @Schema(description = "是否重复文件", example = "false")
    private Boolean isDuplicate;

    /**
     * 下载次数
     */
    @TableField("download_count")
    @Schema(description = "下载次数", example = "0")
    private Integer downloadCount;

    /**
     * 最后下载时间
     */
    @TableField("last_download_time")
    @Schema(description = "最后下载时间", example = "2023-10-27 10:00:00")
    private LocalDateTime lastDownloadTime;

    /**
     * 过期时间
     */
    @TableField("expire_time")
    @Schema(description = "过期时间", example = "2024-10-27 10:00:00")
    private LocalDateTime expireTime;

    /**
     * 是否已删除
     */
    @TableLogic
    @TableField("deleted")
    @Schema(description = "是否已删除", example = "false")
    private Boolean deleted;

    /**
     * 创建时间
     */
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    @Schema(description = "创建时间", example = "2023-10-27 10:00:00")
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    @Schema(description = "更新时间", example = "2023-10-27 10:00:00")
    private LocalDateTime updateTime;
}